import allure
import logging
import pymysql
import requests
from config.config import *
import os


@allure.step("核心步骤2：发送http请求")
def send_http_request(**request_data):
    res = requests.request(**request_data)
    logging.info(f"第2个: http请求完成，响应体文本为:{res.text}")
    allure.attach(f"{res.text}", "http响应结果")
    return res

#@allure.step("对数据库发起请求！")
def send_sql_request(sql,index = 0):
        con = pymysql.Connect(
            # host=DB_HOST,
            # port=DB_PORT,
            # database=DB_DATABASE,
            # user=DB_USER,
            # passwd=DB_PASSWD,
            **eval(os.environ["DB"]),
            charset=DB_CHARSET
        )
        cur = con.cursor()
        cur.execute(sql)
        result = cur.fetchone()[index]
        cur.close()
        con.close()

        return result



